extern "C" { 
    #include "apue.h" 
}   
#include <stdio.h>

#include <unistd.h>
#include <fcntl.h>

#include <stdlib.h> //atoi


int main(int argc ,char** argv)
{    
    if(argc==1)
    {
        err_quit("pls input a num as file descriptor\n");
    }

    int val= fcntl(atoi(argv[1]), F_GETFL,NULL );
    if(val<0)
         err_quit("get file descriptor err\n");


    // O_RDONLY=00,O_WRONLY= 01,O_RDWR=02
    const char* attr[]={"read only","write only","read write","unknown access mode"};
    printf("%d-%s",val& O_ACCMODE,attr[val& O_ACCMODE]);

    if (val & O_APPEND)
        printf(", append");
    if (val & O_NONBLOCK)
        printf(", nonblocking");
    if (val & O_SYNC)
        printf(", synchronous writes");

    putchar('\n');
    exit(0);

}

// > ./exe 0  0</dev/tty
// 0-read only
// > ./exe 1  1>out.o
// > cat out.o
// 1-write only
// > ./exe 2  2>>out.o
// 1-write only, append
// > cat out.o
// 1-write only
// > bash
// $ ./exe 5  5<>out.o
// 2-read write